package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func convertToBin(n int) string {
	result := ""

	for ; n > 0; n /= 2 {
		lsb := n % 2
		result = strconv.Itoa(lsb) + result
	}

	return result
}

func printFile(filename string) {
	file, err := os.Open(filename)
	if err != nil {
		panic(err)
	}
	scanner := bufio.NewScanner(file)

	// go没有 while 就用这样的 for代替
	for scanner.Scan() {
		fmt.Println(scanner.Text())
	}

	// 下面的就是死循环了
	// for {
	// 	fmt.Println(scanner.Text())
	// }
}

func main() {
	fmt.Println("Hello World!")

	fmt.Println(
		convertToBin(5),
		convertToBin(13),
	)

	const filename = "D:\\code\\yl_golang\\mk-golang\\02 基础语法\\abc.txt"
	printFile(filename)
}
